package entity

import "fmt"

// 标准包
type StdPkg struct {
	Id            int64  `json:"id,string"                         gorm:"column:id;comment:请求Id;"`
	CommPortId    int64  `json:"commPortId,string"                         gorm:"column:comm_port_id;comment:协议类型;"`
	CommDealId    int64  `json:"commDealId,string"                         gorm:"column:comm_deal_id;comment:处理程序;"`
	CommProxyId   int64  `json:"commProxyId,string"                         gorm:"column:comm_proxy_id;comment:代理程序;"`
	ClientId      string `json:"clientId"                         gorm:"column:client_id;size:50;comment:客户端;"`
	PhysicalState string `json:"physicalState"                         gorm:"column:physical_state;size:10; DEFAULT:'离线';comment:物理在线状态;"`

	Sid     string         `json:"sid"                         gorm:"column:sid;size:50;comment:联网网关;"`
	CrtDt   string         `json:"CrtDt"                         gorm:"column:crt_dt;size:50;comment:日期;"`
	Events  []StdPkgEvent  `json:"events"                         gorm:"column:events;size:50;comment:事件;"`
	Devices []StdPkgDevice `json:"devices"                         gorm:"column:devices;size:50;comment:设备;"`
}

func (p *StdPkg) GetMemo() string {
	var r = ""
	for _, v := range p.Events {
		r += fmt.Sprintf("%v %v\r\n", v.DevId, v.EventTypeMemo)
	}

	for _, v := range p.Devices {
		for _, v2 := range v.Props {
			if v2.Type == 10 || v2.Type == 20 {
				r += fmt.Sprintf("%v*%v %v %v\r\n", v.Id, v2.Id, v2.Name, v2.Sv)
			} else {
				r += fmt.Sprintf("%v*%v %v %v\r\n", v.Id, v2.Id, v2.Name, v2.Fv)
			}
		}
	}
	return r
}
